/*
 * FileName: bind.cc
 * Author: 李波(Edwin Lee)
 * Date: 2024-07-07 17:31:09
 * Version: 1.0
 * Description:测试bind函数的绑定方法 
 */
#include <functional>
#include <iostream>
using namespace std;

void func(int a,int b)
{
	cout<<"a = "<<a<<"\nb = "<<b<<endl;
}
void func1(int& a,int& b)
{
	cout<<"a = "<<a<<"\nb = "<<b<<endl;
}

struct Foo
{
	void func(int a,int b)
	{
		cout<<"a = "<<a<<"\nb = "<<b<<endl;
	}
};
int main()
{
	//测试bind绑定普通函数,函数只用函数名
	bind(func,placeholders::_1,888)(1111);
	//测试bind绑定普通函数,函数使用函数地址
	bind(&func,222,666)();

	//测试bind绑定类成员函数,函数必须使用地址,第二个参数可用实例也可以用地址
	Foo foo;
	bind(&Foo::func,foo,3333,4444)();
	bind(&Foo::func,&foo,7777,8888)();
	int a = 100;
  int b = 200;
  bind(&func1,a,std::ref(b))();
	return 0;
}
